package sh.ds.el.dao.jdbc;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.JdbcUtils;

public class ObjectArrayRowMapper implements RowMapper {

	@Override
	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		ResultSetMetaData rsmd = rs.getMetaData();
		int columnCount = rsmd.getColumnCount();
		if (columnCount < 2) {
		    return JdbcUtils.getResultSetValue(rs, 1);
		}

		Object[] results = new Object[columnCount];
		for (int i = 0; i < columnCount; i++) {
		    results[i] = JdbcUtils.getResultSetValue(rs, i + 1);
		}
		return results;
	}

}
